<?php $this->load->view('_inc/header');?>
<script>
$(document).ready(function(){
   $('.cadastrar').click(function(){
           var divEditar = $('.popUp');
           $.ajax({
                url: '<?php echo base_url()?>index.php/nucleo/cadastrarNucleo',
                type: 'POST',
                success: function(data){
                    divEditar.html(data);
                    abrePopUp();
                }
        });
    }); 
    
    $('.editar').click(function(){
           var id = $(this).attr('id');
           var divEditar = $('.popUp');
           $.ajax({
                url: '<?php echo base_url()?>index.php/nucleo/editarNucleo/' + id,
                type: 'POST',
                success: function(data){
                    divEditar.html(data);
                    abrePopUp();
                }
        });
    });
    
    $('.excluir').click(function(){      
        if(confirm("Deseja realmente excluir este Nucleo?")){
            var id = $(this).attr('id');
            var url = $(this).attr('name');
            $(this).parent('td').parent('tr').css('background','#ff9999').hide(600);
            $.ajax({
                url: '<?php echo base_url()?>index.php/nucleo/excluirNucleo/' + id,
                type: 'POST',
            });
        }
    });
    
});
</script>

<?php if($this->session->userdata('permissao') == 5){ ?>
    <button class="cadastrar">Novo Núcleo</button>
<?php } ?>
    
<div id="pesquisa">
    <img src="<?php echo base_url()?>public/imagens/icones/pesquisar.png"/>
    <input id="pesquisar">
</div>

<table class="listagem tablesorter">
    <tr>
        <th>Nome</th>
        <th>Gerente</th>
    </tr>
    <?php foreach($nucleos as $nucleo){?>
        <tr>
            <td><?php echo $nucleo->nucleo?></td>
            <td><?php echo $nucleo->gerente?></td>
            <td><?php echo anchor('nucleo/listarMembrosNucleo/'.$nucleo->id,' ','class="icone listar" title="Ver Membros"')?></td>
            <?php if($this->session->userdata('permissao') == 5){ ?>
                <td><a id="<?php echo $nucleo->id?>" class="icone editar" title="Editar"></a></td>
                <td><a id="<?php echo $nucleo->id?>" class="icone excluir" title="Excluir"></a></td>
            <?php } ?>
        </tr>
    <?php }?>
</table>
<?php $this->load->view('_inc/footer'); ?>